﻿Public Class frmJuego
    Dim k As Integer
    Dim lbl() As Label
    Dim j As Integer = 1
    Dim puntos As Integer = 0
    Dim color As Integer = 0
    Dim aciertos As Integer = 0

    Private Sub btnOtraPalabra_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOtraPalabra.Click

        btnOtraPalabra.Enabled = False



        lblpuntos.Text = puntos.ToString
        lblpuntos.Font = New Font("Microsoft San Serif", 40)
        puntos += 10
        For i As Integer = 0 To grpTeclado.Controls.Count - 1
            grpTeclado.Controls(i).Enabled = True
            grpTeclado.Controls(i).BackColor = Drawing.Color.Silver
        Next
        btnOtraPalabra.Text = "SIGUIENTE PALABRA"
        If k <> 0 Then
            For i As Integer = 0 To k
                Me.Controls.RemoveByKey("lbl" & i.ToString)
            Next
        End If
        Dim Palabra As New Clases.Palabra
        Palabra = mijuego.PalabraAlAzar

        If Not IsNothing(Palabra) Then
            lblDescripcion.Text = Palabra.Descripcion


            Array.Resize(lbl, (Palabra.Enunciado.Length))
            Dim x As Integer = 35
            Dim y As Integer = 80
            k = Palabra.Enunciado.Length - 1
            For i As Integer = 0 To Palabra.Enunciado.Length - 1
                lbl(i) = New Label
                lbl(i).AutoSize = True
                lbl(i).Name = "lbl" & i.ToString
                lbl(i).Location = New Point(x, y)
                'lbl(i).Size = New Size(40, 40)
                lbl(i).Text = "___"
                lbl(i).Font = New Font("Microsoft San Serif", 12)
                x += 40
            Next
            Me.Controls.AddRange(lbl)

        Else

            Me.Close()
            MessageBox.Show("Ya no quedan mas palabras, se acabo el juego", "atencion", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            End If
    
    End Sub

    Private Sub btnFinalizar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFinalizar.Click
        Me.Close()
    End Sub
   


   
    Private Sub btnA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnA.Click, btnB.Click, btnC.Click, btnD.Click, btnE.Click, btnF.Click, btnG.Click, btnH.Click, btnI.Click, btnJ.Click, btnK.Click, btnL.Click, btnM.Click, btnN.Click, btnÑ.Click, btnO.Click, btnP.Click, btnQ.Click, btnR.Click, btnS.Click, btnT.Click, btnU.Click, btnV.Click, btnW.Click, btnX.Click, btnY.Click, btnZ.Click
        lblpuntos.Text = puntos.ToString
        Dim txt As Button = TryCast(sender, Button)
        Dim letras As List(Of Integer) = mijuego.PosicionesLetra(txt.Text.ToLower)
        If IsNothing(letras) Then
            color = 1
            If j < 6 Then j += 1

            PictureBox1.ImageLocation = "fotos/" & j & ".jpg"
            'If j = 6 Then

            '    MessageBox.Show(mijuego.Ahorcado)
            '    Me.Close()
            If Not IsNothing(mijuego.Ahorcado) Then
                MessageBox.Show(mijuego.Ahorcado)
                Me.Close()
            End If

        Else
        color = 2
        For i As Integer = 0 To letras.Count - 1
            lbl(letras(i)).Text = txt.Text.ToUpper
        Next
            If Not IsNothing(mijuego.Adivinado) Then
                MessageBox.Show(mijuego.Adivinado)
                btnOtraPalabra.Enabled = True
            End If
        End If

        Select Case txt.Text.ToLower
            Case "a"
                btnA.Enabled = False
                If color = 1 Then
                    btnA.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If
                If color = 2 Then
                    puntos += 2
                    btnA.BackColor = Drawing.Color.Green
                End If


            Case "b"
                btnB.Enabled = False
                If color = 1 Then
                    btnB.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If


                If color = 2 Then
                    btnB.BackColor = Drawing.Color.Green
                    puntos += 2
                End If


            Case "c"
                btnC.Enabled = False

                If color = 1 Then
                    btnC.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If


                If color = 2 Then
                    btnC.BackColor = Drawing.Color.Green
                    puntos += 2
                End If


            Case "d"
                btnD.Enabled = False

                If color = 1 Then
                    btnD.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If


                If color = 2 Then
                    btnD.BackColor = Drawing.Color.Green
                    puntos += 2
                End If

            Case "e"
                btnE.Enabled = False

                If color = 1 Then
                    btnE.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If

                If color = 2 Then
                    btnE.BackColor = Drawing.Color.Green
                    puntos += 2
                End If

            Case "f"
                btnF.Enabled = False

                If color = 1 Then
                    btnF.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If

                If color = 2 Then
                    btnF.BackColor = Drawing.Color.Green
                    puntos += 2
                End If
            Case "g"
                btnG.Enabled = False

                If color = 1 Then
                    btnG.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If

                If color = 2 Then
                    btnG.BackColor = Drawing.Color.Green
                    puntos += 2
                End If

            Case "h"
                btnH.Enabled = False

                If color = 1 Then
                    btnH.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If

                If color = 2 Then
                    btnH.BackColor = Drawing.Color.Green
                    puntos += 2
                End If

            Case "i"
                btnI.Enabled = False

                If color = 1 Then
                    btnI.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If

                If color = 2 Then
                    btnI.BackColor = Drawing.Color.Green
                    puntos += 2
                End If

            Case "j"
                btnJ.Enabled = False

                If color = 1 Then
                    btnJ.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If

                If color = 2 Then
                    btnJ.BackColor = Drawing.Color.Green
                    puntos += 2
                End If

            Case "k"
                btnK.Enabled = False

                If color = 1 Then
                    btnK.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If

                If color = 2 Then
                    btnK.BackColor = Drawing.Color.Green
                    puntos += 2
                End If

            Case "l"
                btnL.Enabled = False

                If color = 1 Then
                    btnL.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If

                If color = 2 Then
                    btnL.BackColor = Drawing.Color.Green
                    puntos += 2
                End If

            Case "m"
                btnM.Enabled = False

                If color = 1 Then
                    btnM.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If

                If color = 2 Then
                    btnM.BackColor = Drawing.Color.Green
                    puntos += 2
                End If
            Case "n"
                btnN.Enabled = False

                If color = 1 Then
                    btnN.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If

                If color = 2 Then
                    btnN.BackColor = Drawing.Color.Green
                    puntos += 2
                End If

            Case "ñ"
                btnÑ.Enabled = False

                If color = 1 Then
                    btnÑ.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If

                If color = 2 Then
                    btnÑ.BackColor = Drawing.Color.Green
                    puntos += 2
                End If

            Case "o"
                btnO.Enabled = False

                If color = 1 Then
                    btnO.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If

                If color = 2 Then
                    btnO.BackColor = Drawing.Color.Green
                    puntos += 2
                End If

            Case "p"
                btnP.Enabled = False

                If color = 1 Then
                    btnP.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If

                If color = 2 Then
                    btnP.BackColor = Drawing.Color.Green
                    puntos += 2
                End If

            Case "q"
                btnQ.Enabled = False

                If color = 1 Then
                    btnQ.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If

                If color = 2 Then
                    btnQ.BackColor = Drawing.Color.Green
                    puntos += 2
                End If

            Case "r"
                btnR.Enabled = False

                If color = 1 Then
                    btnR.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If

                If color = 2 Then
                    btnR.BackColor = Drawing.Color.Green
                    puntos += 2
                End If

            Case "s"
                btnS.Enabled = False

                If color = 1 Then
                    btnS.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If

                If color = 2 Then
                    btnS.BackColor = Drawing.Color.Green
                    puntos += 2
                End If

            Case "t"
                btnT.Enabled = False

                If color = 1 Then
                    btnT.BackColor = Drawing.Color.Red
                    puntos -= 1

                End If

                If color = 2 Then
                    btnT.BackColor = Drawing.Color.Green
                    puntos += 2
                End If

            Case "u"
                btnU.Enabled = False

                If color = 1 Then
                    btnU.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If

                If color = 2 Then
                    btnU.BackColor = Drawing.Color.Green
                    puntos += 2
                End If

            Case "v"
                btnV.Enabled = False

                If color = 1 Then
                    btnV.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If

                If color = 2 Then
                    btnV.BackColor = Drawing.Color.Green
                    puntos += 2
                End If

            Case "w"
                btnW.Enabled = False

                If color = 1 Then
                    btnW.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If

                If color = 2 Then
                    btnW.BackColor = Drawing.Color.Green
                    puntos += 2
                End If

            Case "x"
                btnX.Enabled = False

                If color = 1 Then
                    btnX.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If

                If color = 2 Then
                    btnX.BackColor = Drawing.Color.Green
                    puntos += 2
                End If

            Case "y"
                btnY.Enabled = False

                If color = 1 Then
                    btnY.BackColor = Drawing.Color.Red
                    puntos -= 1
                End If

                If color = 2 Then
                    puntos += 2
                    btnY.BackColor = Drawing.Color.Green
                End If

            Case "z"
                btnZ.Enabled = False

                If color = 1 Then
                    puntos -= 1
                    btnZ.BackColor = Drawing.Color.Red
                End If

                If color = 2 Then
                    btnZ.BackColor = Drawing.Color.Green
                    puntos += 2
                End If

        End Select
    End Sub

    Private Sub frmJuego_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        PictureBox1.ImageLocation = "fotos/" & "1.jpg"
    End Sub
End Class
